// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import './assets/css/reset.css'
import './assets/icon/style.css'
import './assets/css/animate.css'
import './assets/css/elementDatePicker.css'

import "babel-polyfill"
// 引入echarts
import echarts from 'echarts'

Vue.prototype.$echarts = echarts
//引入toast
// import 'cxlt-vue2-toastr/dist/css/cxlt-vue2-toastr.css'
// import CxltToastr from 'cxlt-vue2-toastr'
// //全局toast提示
// let toastrConfigs = {
//   position: 'top center',
//   timeOut: 3000,
//   color:'rgba(55,55,55,0.5)',
//   closeButton:false,
// }
// Vue.use(CxltToastr,toastrConfigs)
//引入element-ui
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './assets/css/authority.css'
Vue.use(ElementUI);
//引入axios
import axios from 'axios'
Vue.prototype.$axios = axios
window.axios = axios
// 拦截器
axios.interceptors.request.use(function (config) {
  /*console.log('拦截器：start.config:' + JSON.stringify(config))*/
  return config
}, function (error) {
  // Do something with request error
  /*console.log('拦截器：start.error:' + JSON.stringify(error))*/
  return Promise.reject(error)
})
axios.interceptors.response.use(function (response) {
  // Do something with response data
  /*console.log('拦截器：finish.response:' + JSON.stringify(response))*/
  if(response.data.code==403){
    // window.location.href = '#/welcome'
    vue.changeNav = !vue.changeNav
    vue.$message({
      message: '您没有权限',
      center: true,
      type: 'info'
    })
  }else if(response.data.code==500){
    window.location.href = '#/welcome'
    vue.changeNav = !vue.changeNav
    vue.$message({
      message: '您没有权限',
      center: true,
      type: 'info'
    })
  }else if(response.data.code==405){
    // window.location.href = '#/'
    // vue.$refs.goLogin.show();
    vue.changeNav = !vue.changeNav
    vue.isGoLogin = true;
    vue.goLoginTxt = response.data.message;
  }else{
    return response
  }
}, function (error) {
  // Do something with response error
  /*console.log('拦截器：finish.error:' + JSON.stringify(error))*/
  return Promise.reject(error)
})


// 改变totas提示时间
import { Message } from 'element-ui';
Vue.prototype.$message = (obj)=>{
  obj.duration=1000;
  Message(obj);
};


Vue.config.productionTip = false


// 字数太长省略
Vue.filter('filterLogText', function (value,leng=7) {
  if(value.length<=leng){
    return value;
  }else{
    return value.slice(0,leng)+'...';
  }
})

/* eslint-disable no-new */
const vue = new Vue({
  el: '#app',
  data(){
    return{
      isGoLogin:false,
      goLoginTxt:'无session',
      changeNav:false
    }
  },
  methods:{
    clickConfirm(){
      this.isGoLogin = false;
    }
  },
  router,
  components: { App },
  template: `<App :isGoLogin="isGoLogin" :goLoginTxt="goLoginTxt" @clickConfirm="clickConfirm" :changeNav='changeNav'/>`
})
